import dayjs from 'dayjs'
import rt from 'dayjs/plugin/relativeTime'
import 'dayjs/locale/zh-cn'
import store from '@/store'
export const dateFormat = (val, format = 'YYYY-MM-DD') => {
  if (isNaN(val)) {
    return val
  }
  val = parseInt(val)
  return dayjs(val).format(format)
}
export const relativeTime = (val) => {
  if (isNaN(val)) {
    return val
  }
  val = parseInt(val)
  dayjs.extend(rt)
  return dayjs()
    .locale(store.getters.lang === 'en' ? 'en' : 'zh-cn')
    .to(dayjs(val))
}
